
//-----------------MATRICES---------------
float4x4 xWorld: World;				
float4x4 xView: View;
float4x4 xProjection: Projection;
float4x4 xRotationMatrix;


//-----------------TEXTURES---------------

Texture xTexture;
sampler ColoredTextureSampler = sampler_state { texture = <xTexture> ;
    magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};

textureCUBE xCubeShadowMap; 
samplerCUBE CubeShadowMapSampler = sampler_state
{
	Texture = <xCubeShadowMap>;
    MipFilter = NONE;
    MinFilter = NONE;
    MagFilter = NONE;
    AddressU = wrap;
    AddressV = wrap;
};

Texture xShadowSrc;
sampler ShadowSampler = sampler_state { texture = <xShadowSrc> ;
    magfilter = NONE; minfilter = NONE; mipfilter=NONE; AddressU = clamp; AddressV = clamp;};

Texture xShadowSrcA;
sampler ShadowSamplerA = sampler_state { texture = <xShadowSrcA> ;
    magfilter = NONE; minfilter = NONE; mipfilter=NONE; AddressU = clamp; AddressV = clamp;};
    
Texture xShadowSrcB;
sampler ShadowSamplerB = sampler_state { texture = <xShadowSrc> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};    

Texture xDeffered1;
sampler DefferedSampler1 = sampler_state { texture = <xDeffered1> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};

Texture xDeffered2;
sampler DefferedSampler2 = sampler_state { texture = <xDeffered2> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};

Texture xDeffered3;
sampler DefferedSampler3 = sampler_state { texture = <xDeffered3> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};

Texture xDeffered4;
sampler DefferedSampler4 = sampler_state { texture = <xDeffered4> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};

Texture xSunBrush;
sampler SunSampler = sampler_state { texture = <xSunBrush> ;
    magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter=ANISOTROPIC; AddressU = clamp; AddressV = clamp;};


//--------------- CONSTANTS ---------------

float Density;
float Decay;
float Weight;
float Exposure;
float4 ScreenLightPos;

float xMagnitude;
float xTime2;
float4 g_vSunPosition;


float4 xLightPosition;
float4 xAmbientLight;
float4 xCameraPosition;

float4  g_vSampleOffsets0;
float4  g_vSampleOffsets1;
float4  g_vSampleOffsets2;
float4  g_vSampleOffsets3;
float4  g_vSampleOffsets4;
float4  g_vSampleOffsets5;
float4  g_vSampleOffsets6;
float4  g_vSampleOffsets7;
float4  g_vSampleOffsets8;
float4  g_vSampleOffsets9;
float4  g_vSampleOffsets10;
float4  g_vSampleOffsets11;
float4  g_vSampleOffsets12;
float4  g_vSampleOffsets13;
float4  g_vSampleOffsets14;

float xMeshID;
//------------------- STRUCTS -------------------   

 struct PS_MRT_Output
    {
        float4 C1 : COLOR0;
        float4 C2 : COLOR1;
        float4 C3 : COLOR2;
        float4 C4 : COLOR3;        
    };


struct BufferToVertex
{
float3 Pos : POSITION;
float4 Normal : NORMAL;
float4 UV : TEXCOORD0;

};


struct VertexToPixel
{
float4 Pos:POSITION;
float4 Orig_Pos:TEXCOORD1;
float4 UV:TEXCOORD0;
float4 Normal: TEXCOORD2;
float4 TexWeights: TEXCOORD3;
float4 Pos3D:TEXCOORD4;
float4 Pos2D:TEXCOORD5;
};


struct PixelToFrame
{
float4 Color:COLOR;
float Depth:DEPTH;
};

struct PixelToFrameMRT
{
float4 Color0:COLOR0;
float4 Color1:COLOR1;
float Depth:DEPTH;
};


struct PSCubeIn
{
    float4 oPositionLight : POSITION;
    float3 lightVec       : TEXCOORD0;
};

// Gaussian filter vertex shader
struct VSOUTPUT_BLUR
{
   float4 vPosition    : POSITION;
   float2 vTexCoord    : TEXCOORD0;
};

//---------------------- HELPERS ------------------------

bool IsInShadow(float3 LightPos, float3 inObjPos)
{
     float4 PLightDirection = 0.0f;
     PLightDirection.xyz = LightPos.xyz - inObjPos;
     float distance = length(PLightDirection.xyz);
     PLightDirection.xyz = PLightDirection.xyz / distance;
     
    
     //sample depth from cubic shadow map                         		 
	 float shadowMapDepth = texCUBE(CubeShadowMapSampler, float4(-(PLightDirection.xyz), 0.0f)).r;
	 //depth comparison
	 if(distance - shadowMapDepth > -0.005)   return true;	      	
	 else return false;
}



//---------------------- SHADERS ------------------------


// ---- CUBE DEPTH --------------------------------

PSCubeIn cubedepthVS( float4 inPosition : POSITION )
{
    PSCubeIn output;

    float4x4 WorldViewProj;
    WorldViewProj=mul(xWorld,xView);
    WorldViewProj=mul(WorldViewProj,xProjection);
    
    float4 positionW = mul( inPosition, xWorld );
    output.oPositionLight = mul( inPosition, WorldViewProj );
    
    output.lightVec = xLightPosition.xyz - positionW.xyz; 

    return output;
}  

float4 cubedepthPS( PSCubeIn In ) : COLOR0
{
    float3 Color=float3(1,1,1)*(length(In.lightVec)+0.2f);
	return float4(Color.xyz,1); 
   
} 


//---------- TEXTURED ---------------

VertexToPixel texturedVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  OUT.Pos=mul(float4(IN.Pos.xyz,1.0), WorldViewProj);
  OUT.Pos2D=OUT.Pos;
  OUT.Pos3D=mul(float4(IN.Pos.xyz,1.0),xWorld);
  OUT.Orig_Pos=float4(IN.Pos.xyz,1.0);
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  OUT.Normal=IN.Normal;
	return OUT;
}

PixelToFrame texturedPS(VertexToPixel IN) 
{
PixelToFrame OUT = (PixelToFrame)0;
OUT.Depth=IN.Pos2D.z/IN.Pos2D.w;
float4 L =xLightPosition - IN.Pos3D;
L=normalize(L);
float4 Nm = mul(normalize(IN.Normal),xRotationMatrix);
float LightIntensity = dot(Nm,L);

float2 tex = ((IN.Pos2D.xy/IN.Pos2D.w) + float2(1.0f,1.0f))/2.0f; 
tex.y = 1.0-tex.y;
LightIntensity= tex2D(ShadowSamplerB, tex).r; //ZLE BIERZE PUNKT Z TEKSTURY!!!

//float LightIntensityA= tex2D(ShadowSamplerA, tex).r; //ZLE BIERZE PUNKT Z TEKSTURY!!!
//float LightIntensityB= tex2D(ShadowSamplerB, tex).r; //ZLE BIERZE PUNKT Z TEKSTURY!!!
//OUT.Color = float4(LightIntensity,LightIntensityA,LightIntensityB,1.0f);

//if (LightIntensity<0.1f) LightIntensity=0.1f;
OUT.Color = saturate(tex2D(ColoredTextureSampler, IN.UV)*LightIntensity+xAmbientLight);
return OUT;
}

//---------- SHADOWS ---------------

VertexToPixel shadowsVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  OUT.Pos=mul(float4(IN.Pos.xyz,1.0), WorldViewProj);
  OUT.Pos2D=OUT.Pos;
  OUT.Pos3D=mul(float4(IN.Pos.xyz,1.0),xWorld);
  OUT.Orig_Pos=float4(IN.Pos.xyz,1.0);
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  OUT.Normal=IN.Normal;
	return OUT;
}

PixelToFrame shadowsPS(VertexToPixel IN) 
{
PixelToFrame OUT = (PixelToFrame)0;
OUT.Depth=IN.Pos2D.z/IN.Pos2D.w;
float LightIntensity = 1.0f;
if (IsInShadow(xLightPosition,IN.Pos3D.xyz)) LightIntensity=0.1f;
OUT.Color = float4(LightIntensity,IN.Pos2D.z/10.0f,xMeshID,0.0f); //(OUT.Depth+1.0f)/2.0f
return OUT;
}


//----------- TEXTURED (NO LIGHTING) ----------
VertexToPixel nolighttexturedVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  OUT.Pos=mul(float4(IN.Pos.xyz,1.0), WorldViewProj);
  OUT.Pos2D=OUT.Pos;
  OUT.Pos3D=mul(float4(IN.Pos.xyz,1.0),xWorld);
  OUT.Orig_Pos=float4(IN.Pos.xyz,1.0);
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  OUT.Normal=IN.Normal;
  return OUT;
}

PixelToFrame nolighttexturedPS(VertexToPixel IN) 
{
PixelToFrame OUT = (PixelToFrame)0;
OUT.Depth=IN.Pos2D.z/IN.Pos2D.w;
OUT.Color = saturate(tex2D(ColoredTextureSampler, IN.UV)+xAmbientLight);

return OUT;
}

//-----------------------------------------------------

VSOUTPUT_BLUR VS_Blur( float4 inPosition : POSITION, float2 inTexCoord : TEXCOORD0 )
{
   // Output struct
   VSOUTPUT_BLUR OUT = (VSOUTPUT_BLUR)0;
   // Output the position
   OUT.vPosition = inPosition;
   // Output the texture coordinates
   OUT.vTexCoord = inTexCoord;
   return OUT;
}
// Horizontal blur pixel shader
float4 PS_Blur( VSOUTPUT_BLUR IN ): COLOR0
{
   // Accumulated color
   float4 vAccum = float4( 0.0f, 0.0f, 0.0f, 0.0f );
   float4 vTmp = float4( 0.0f, 0.0f, 0.0f, 0.0f );
   float vIle = 1;	
   // Sample the taps (g_vSampleOffsets holds the texel offsets
   // and g_fSampleWeights holds the texel weights)

      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets0.xy );
      float baseZ = vTmp.z;//vTmp.y;
      vAccum += vTmp;// * g_vSampleOffsets0.z;


//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets1.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets1.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets2.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets2.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets3.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets3.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets4.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets4.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets5.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets5.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets6.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets6.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets7.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets7.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets8.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets8.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets9.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets9.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets10.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets10.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets11.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets11.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets12.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets12.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets13.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets13.z;
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets14.xy );
//      if ( abs(vTmp.y-baseZ)<0.001 ) vAccum += vTmp * g_vSampleOffsets14.z;


      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets1.xy );
      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets2.xy );
      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets3.xy );
      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets4.xy );
      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets5.xy );
      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
//      vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets6.xy );
//      if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets7.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets8.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets9.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets10.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets11.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets12.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets13.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}
 //     vTmp = tex2D( ShadowSampler, IN.vTexCoord + g_vSampleOffsets14.xy );
 //     if ( abs(vTmp.z-baseZ)<0.005 ) {vAccum += vTmp; vIle += 1;}

   vAccum.x /= vIle;

   vAccum.z = baseZ;  
   vAccum.y = 0.0f;                                                             
   return vAccum;
}



PS_MRT_Output PS_Mrt( VSOUTPUT_BLUR IN )
{

   PS_MRT_Output OUT;
   
   OUT.C1 = float4(1.0f, 0.0f,0.0f,0.0f);
   OUT.C2 = float4(0.0f,1.0f,0.0f,0.0f);
   OUT.C3 = float4(0.0f, 0.0f,1.0f,0.0f);
   OUT.C4 = float4(0.0f,1.0f,1.0f,1.0f);
   
   return OUT;
}

float4 PS_Mrt2( VSOUTPUT_BLUR IN ): COLOR0
{
   float4 vD1 = tex2D( DefferedSampler1, IN.vTexCoord);
   float4 vD2 = tex2D( DefferedSampler2, IN.vTexCoord);
   float4 vD3 = tex2D( DefferedSampler3, IN.vTexCoord);
   float4 vD4 = tex2D( DefferedSampler4, IN.vTexCoord);
   
   float4 vAccum = float4( vD1.r, vD2.g, vD3.b, vD4.a);
   return vAccum;
}


//----------- tree
VertexToPixel treeVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  WorldViewProj=mul(xView,xProjection);

  float4 vertex = mul(float4(IN.Pos.xyz,1.0), xWorld);
	float amplitude = xMagnitude * vertex.y;
	float4 wave = amplitude * float4(sin(xTime2 + vertex.x), 0, cos(xTime2 + vertex.z), 0);
	vertex = vertex + wave;
 

  OUT.Pos=mul(vertex, WorldViewProj);
  OUT.Pos2D=OUT.Pos;
  OUT.Pos3D=mul(vertex,xWorld);
  OUT.Orig_Pos=vertex;
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  OUT.Normal=mul(IN.Normal,xWorld);
  
  return OUT;
}

PixelToFrameMRT treePS(VertexToPixel IN) 
{
PixelToFrameMRT OUT = (PixelToFrameMRT)0;
OUT.Depth=IN.Pos2D.z/IN.Pos2D.w;
float4 LightVector = normalize(xLightPosition - IN.Orig_Pos);
float LightIntensity = max(dot(LightVector,normalize(mul(IN.Normal,xRotationMatrix))),0.0);

float4 texColor = tex2D(ColoredTextureSampler, IN.UV);
clip(texColor.a - 0.7);
OUT.Color0 = saturate(texColor * LightIntensity * 0.5 + texColor * 0.5 + xAmbientLight);
OUT.Color1 = float4(0,0,0,1);
return OUT;
}

//--------SKY

VertexToPixel skyVS(BufferToVertex IN)
{
  VertexToPixel OUT = (VertexToPixel)0;
  float4x4 WorldViewProj;
  WorldViewProj=mul(xWorld,xView);
  WorldViewProj=mul(WorldViewProj,xProjection);
  float4 vertex = float4(IN.Pos.xyz,1.0);
  OUT.Pos=mul(vertex, WorldViewProj);
  OUT.Pos2D=OUT.Pos;
  OUT.Pos3D=mul(vertex,xWorld);
  OUT.Orig_Pos=vertex;
  OUT.UV=float4(IN.UV.xy,1.0,1.0);
  OUT.Normal=mul(IN.Normal,xWorld);
  return OUT;
}

PixelToFrameMRT skyPS(VertexToPixel IN) 
{
PixelToFrameMRT OUT = (PixelToFrameMRT)0;
OUT.Depth=IN.Pos2D.z/IN.Pos2D.w;
float4 texColor = tex2D(ColoredTextureSampler, IN.UV);
OUT.Color0 = saturate(texColor + xAmbientLight);
OUT.Color1 = float4(0,0,0,1);
return OUT;
}



//--------The SUN
VSOUTPUT_BLUR sunVS( float4 inPosition : POSITION, float2 inTexCoord : TEXCOORD0 )
{
   VSOUTPUT_BLUR OUT = (VSOUTPUT_BLUR)0;
   OUT.vPosition = inPosition + g_vSunPosition;
   OUT.vTexCoord = inTexCoord;
   return OUT;
}

PixelToFrameMRT sunPS( VSOUTPUT_BLUR IN ) 
{
PixelToFrameMRT OUT = (PixelToFrameMRT)0;
OUT.Depth=0.8f;    
OUT.Color0 = float4(0,0,0,1);   //float4(tex2D(SunSampler, IN.vTexCoord).xyz,1);
OUT.Color1 = float4(tex2D(SunSampler, IN.vTexCoord).xyz,1);
return OUT;
}

// SUN Shafts
float4 PS_Shaft( VSOUTPUT_BLUR IN ): COLOR0
{
  float2 texCoord = IN.vTexCoord.xy;
  half2 deltaTexCoord = (texCoord - ScreenLightPos.xy);
  deltaTexCoord *= 1.0f / 64 * Density;
  half3 color = tex2D(SunSampler, texCoord);
  //half3 colorO = tex2D(DefferedSampler1, texCoord);
  half illuminationDecay = 1.0f;
  for (int i = 0; i < 64; i++)
  {
    texCoord -= deltaTexCoord;
    half3 sample = tex2D(SunSampler, texCoord);
    sample *= illuminationDecay * Weight;
    color += sample;
    illuminationDecay *= Decay;
  }
//return float4( color * Exposure + colorO, 1);
return float4( color * Exposure, 1);
}



// ------------ TECHNIQUES --------------

technique nolighttextured {
	pass p0 {
		VertexShader = compile vs_3_0 nolighttexturedVS();
		PixelShader = compile ps_3_0 nolighttexturedPS();
	}
}

technique textured {
	pass p0 {
		VertexShader = compile vs_3_0 texturedVS();
		PixelShader = compile ps_3_0 texturedPS();
	}
}


technique cubedepth{
	pass p0 {
		
		VertexShader = compile vs_3_0 cubedepthVS();
		PixelShader = compile ps_3_0 cubedepthPS();
	}
}

technique shadows {
	pass p0 {
		VertexShader = compile vs_3_0 shadowsVS();
		PixelShader = compile ps_3_0 shadowsPS();
	}
}

technique blur
{
	pass p0
	{
		Lighting	= False;
		CullMode	= None;
		
		VertexShader = compile vs_3_0 VS_Blur();
		PixelShader  = compile ps_3_0 PS_Blur();
	}
}

technique mrt
{
	pass p0
	{
		VertexShader = compile vs_3_0 VS_Blur();
		PixelShader  = compile ps_3_0 PS_Mrt();
	}
}

technique mrt2
{
	pass p0
	{
		VertexShader = compile vs_3_0 VS_Blur();
		PixelShader  = compile ps_3_0 PS_Mrt2();
	}
}

technique texturedalpha {
	pass p0 {
	
//                AlphaBlendEnable = true;
//		BlendOp = ADD;
//		SrcBlend = SRCALPHA;
//		DestBlend = INVSRCALPHA;

//    SrcBlendAlpha = ZERO;
//    DestBlendAlpha = ZERO;
//    BlendOpAlpha = ADD;	
	
		VertexShader = compile vs_3_0 treeVS();
		PixelShader = compile ps_3_0 treePS();

	}
}

technique sky {
	pass p0 {
	
		VertexShader = compile vs_3_0 skyVS();
		PixelShader = compile ps_3_0 skyPS();
	}
}


technique sun {
	pass p0 {
                AlphaBlendEnable = true;
		BlendOp = ADD;
		SrcBlend = ONE;
		DestBlend = ONE;

    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;	
	
		VertexShader = compile vs_3_0 sunVS();
		PixelShader = compile ps_3_0 sunPS();
	}
}


technique shaft {
	pass p0 {

		Lighting	= False;
		CullMode	= None;
        AlphaBlendEnable = true;
		BlendOp = ADD;
		SrcBlend = ONE;
		DestBlend = ONE;

    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;	
        		
		VertexShader = compile vs_3_0 VS_Blur();
		PixelShader  = compile ps_3_0 PS_Shaft();

	}
}